package activiti2;

import org.activiti.engine.HistoryService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.history.HistoricVariableInstance;
import org.junit.Test;

import java.util.List;

/**
 * 流程执行历史记录
 */
public class LiuChengZhiXingLiShiJiLu {

    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

    //查询历史流程实例  【act_hi_procinst】
    @Test
    public void findHistoricProcessInstance(){
        HistoryService historyService = processEngine.getHistoryService();
        List<HistoricProcessInstance> list = historyService.createHistoricProcessInstanceQuery()
                .processDefinitionId("myProcess_1:1:4")//流程定义ID
                .list();
        if(list != null && list.size()>0){
            for (HistoricProcessInstance hpi:list) {
                System.out.println(hpi.getId()+" "+hpi.getStartTime()+" "+hpi.getEndTime());
            }
        }
    }

    /**
     *
     * 查询历史活动 【act_hi_actinst】
     * 问题：HistoricActivityInstance对应哪个表
     * 问题：HistoricActivityInstance和HistoricTaskInstance有什么区别
     *
     */
    @Test
    public void findHisActivitiList(){
        String processInstanceId = "17501";
        List<HistoricActivityInstance> list = processEngine.getHistoryService()
                .createHistoricActivityInstanceQuery()
                .processInstanceId(processInstanceId)
                .list();
        if(list != null && list.size()>0){
            for (HistoricActivityInstance hai : list) {
                System.out.println(hai.getId() + " " +hai.getActivityName());
            }
        }

    }

    /**
     * 查询历史流程变量 【act_hi_varinst】
     *
     */
    @Test
    public void findHisVariablesList(){
        String processInstanceId = "17501";
        List<HistoricVariableInstance> list = processEngine.getHistoryService()
                .createHistoricVariableInstanceQuery()
                .processInstanceId(processInstanceId)
                .list();
        if(list != null && list.size()>0){
            for (HistoricVariableInstance hvi:list) {
                System.out.println(hvi.getId()+" "+hvi.getVariableName()+" "+hvi.getValue());
            }
        }

    }



}
